package cn.edu.zzuli.service;

import cn.edu.zzuli.bean.User;
import cn.edu.zzuli.mapper.UserMapper;
import org.aspectj.lang.annotation.AfterReturning;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Component
public class UserService{

    @Autowired
    UserMapper userMapper;

    @Transactional(readOnly=true)
    public List<User> getUsers() {
        return userMapper.getUsers();
    }

    @Transactional(rollbackFor = java.lang.ArithmeticException.class)
    public void addUser(User user) {
        userMapper.addUser(user);

        //这里故意报错
        int a = 0, b = 0;
        System.out.println(a/b);
    }
}
